package com.jandar.logging.impl;

import java.io.PrintStream;

import com.jandar.logging.BaseLogger;
import com.jandar.logging.Logger;
import com.jandar.logging.LoggerFactory;

/**
 * 控制台Logger。
 * 
 * @author pqj
 * @version 2009-6-2
 */
public class ConsoleLogger extends BaseLogger {

	private PrintStream stream = System.out;

	public ConsoleLogger(String name) {
		super(name);
	}

	public void error(String str) {
		stream.println(super.format(Logger.ERROR_MSG, str));
	}

	public void error(Throwable ex) {
		stream.println(super.format(Logger.ERROR_MSG, ex));
		ex.printStackTrace(stream);
	}

	public void info(String str) {
		stream.println(super.format(Logger.INFO_MSG, str));
	}

	public void info(Throwable ex) {
		stream.println(super.format(Logger.INFO_MSG, ex));
		ex.printStackTrace(stream);
	}

	public void waring(String str) {
		stream.println(super.format(Logger.WARING_MSG, str));
	}

	public void waring(Throwable ex) {
		stream.println(super.format(Logger.WARING_MSG, ex));
		ex.printStackTrace(stream);
	}

	public void debug(String str) {
		if (LoggerFactory.isDebug()) {
			stream.println(super.format(Logger.DEBUG_MSG, str));
		}
	}

	public void debug(Throwable ex) {
		if (LoggerFactory.isDebug()) {
			stream.println(super.format(Logger.DEBUG_MSG, ex));
			ex.printStackTrace(stream);
		}
	}
}
